package demo2;

import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 何华树
 * Date: 2024-09-04
 * Time: 19:13
 */
public class Dog {
    public String name;
    public int age;

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void eat() {
        System.out.println(this.name+"正在吃狗粮...");
    }

    public boolean equals(Object obj) {
        if(this == obj) {
            return true;
        }
        if(!(obj instanceof Dog)) {
            return false;
        }
        if(obj == null) {
            return false;
        }
        Dog tmp = (Dog)obj;
        return this.age == tmp.age && this.name.equals(tmp.name);
    }

    public int hashCode() {
        return Objects.hash(name,age);
    }

}
